package com.example.chapter05;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

public class RadioHorizontalActivity extends AppCompatActivity implements RadioGroup.OnCheckedChangeListener {

    private TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_radio_horizontal);
        RadioGroup radio_group = findViewById(R.id.rg_gender);
        RadioButton radioButtonFemale = findViewById(R.id.rbFemale);
        RadioButton radioButtonMale = findViewById(R.id.rbMale);
        textView = findViewById(R.id.tv_result);

        radio_group.setOnCheckedChangeListener(this);
    }

    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        if (checkedId == R.id.rbFemale) {
            textView.setText("女性");
        } else if (checkedId == R.id.rbMale) {
            textView.setText("男性");
        }
    }
}